package com.xms.dependency.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xms.core.module.ModuleCollection;
import com.xms.datacore.service.DeleterService;
import com.xms.dependency.XmsDependencyException;
import com.xms.dependency.entity.Dependency;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.sql.SQLException;
import java.util.UUID;

/**
 * <p>
 * DependencyDeleterService
 * </p>
 *
 * @author migo
 * @since 2021/10/23
 */
@Service
public class DependencyDeleterService extends DeleterService<Dependency> implements IDependencyDeleterService {

    @Override
    public boolean deleteByDependentId(int dependentComponentType, UUID... dependentId) throws SQLException, XmsDependencyException {
        Assert.notEmpty(dependentId, "dependentId");
        return super.deleteMany(new LambdaQueryWrapper<Dependency>()
                .eq(Dependency::getDependentcomponenttype, dependentComponentType)
                .in(Dependency::getDependentobjectid, dependentId));
    }

    @Override
    public boolean deleteByDependentId(String dependentComponentName, UUID... dependentId) throws SQLException, XmsDependencyException {
        return this.deleteByDependentId(ModuleCollection.getIdentity(dependentComponentName), dependentId);
    }

    @Override
    public boolean deleteByRequiredId(int requiredComponentType, UUID... requiredId) throws SQLException, XmsDependencyException {
        Assert.notEmpty(requiredId, "requiredId");
        return super.deleteMany(new LambdaQueryWrapper<Dependency>()
                .eq(Dependency::getRequiredcomponenttype, requiredComponentType)
                .in(Dependency::getRequiredobjectid, requiredId));
    }

    @Override
    public boolean deleteByRequiredId(String requiredComponentName, UUID... requiredId) throws SQLException, XmsDependencyException {
        return this.deleteByRequiredId(ModuleCollection.getIdentity(requiredComponentName), requiredId);
    }
}
